<?php
$id = intval($_GET['id']);
if(isset($_POST['ajax_pagination'])){
			$cache=new cache;
			$og_url=$_POST['url']."/";
			$_GET['page']=$_POST['page'];
			$sql ='select id,ten,thutu,alias,thutu,views,time_upload,user_upload from truyen_chuong where truyen_id='.$id.' and  trangthai=1 and xoa=0 order by thutu desc';
			$sql2='select id from truyen_chuong where truyen_id='.$id.' and  trangthai=1 and xoa=0';
			
			$pager = new Pagination2($sql, 30, 5,$og_url,0);
			$pager->ajax=1;
			$pager->setDebug(false);
			$cache=new cache;
			$data['truyen']['info'] = $pager->paginate($cache,$sql2);
			$data['truyen']['nav']	= $pager->renderFullNav();
			
			//Render data-------------
				 if($data['truyen']['nav'])
				 echo "<div class='row' style='text-align:center'>".$data['truyen']['nav']."</div>";
				if($data['truyen']['info']){
						$url=$_POST['url'];
						echo truyen_render_chapter_item($data['truyen']['info'],$_POST['alias']);
				 }
				 if($data['truyen']['nav'])
				 echo "<div class='row' style='text-align:center'>".$data['truyen']['nav']."</div>";
				 exit();
}



	$data=truyenf1_get_truyen($id);
	//GET FOLLOWED
	if($_SESSION['user']){
		$model = new model2();
		$model->select = "id";
		$model->where = "truyen_id = '" . $id . "' AND username='" . $_SESSION['user']['username'] . "'";
		$model->getdata('truyen_history');
		$resultHistory = $model->fetchOne();
	
		if($resultHistory){
			$data['is_followed'] = true;
		}else{
			$data['is_followed'] = false;
		}
	}
	

	
	//echo $data['tag3'];
	//
	
	//GET 30 ITEM OF CHUONG 
			$cache=new cache;
			$og_url=truyenf1_url_truyen($data['id'],$data['alias'])."/";
	
			$sql ='select id,thutu,ten,alias,thutu,views,time_upload,user_upload from truyen_chuong where truyen_id='.$id.' and  trangthai=1 and xoa=0 order by thutu desc';
			$sql2='select id from truyen_chuong where truyen_id='.$id.' and  trangthai=1 and xoa=0';
			
			$pager = new Pagination2($sql, 30, 5,$og_url,0);
			$pager->ajax=1;
			$pager->setDebug(false);
			$cache=new cache;
			$data['chuong']['data'] = $pager->paginate($cache,$sql2);
			$data['chuong']['nav']	= $pager->renderFullNav();
	
	//$data['chuong_list']=truyenf1_truyen_get_chuong_list($id);
	
 //get the loai truyen cung tac gia ----------
 //query facebook, udpate sau
 /*
	$fb=new shareCount(url_truyen($data['id'],$data['alias']));
	$count=$fb->get_fb();
	$db=new db;
	$db->connect();
	$db->nonquery("update truyen set likes=".$count['like']." , comments=".$count['comment']." where id=$id");
	$db->close();
	*/
// End get truyen cung tac gia-------

   	//Lay the loai 2, lay duoc list chuong, update view, update so chuong hien co,update view
	
	//HEADER TITLE,KEYWORD,DESCRIPION
	
	$data1['title']="Đọc truyện ".encode($data['ten']);
	$data1['mota']=short_str($data['noidung'],150);
	$data1['keyword']=$data['ten'].",".$data['alias'].", doc truyen ".$data['ten'].",doc truyen ".$data['ten']." full,".$data['ten']." tron bo";
	$data1['canonical']=truyenf1_url_truyen($data['id'],$data['alias']);

		$og='<meta property="og:type" content="book" />
<meta property="og:image" content="http://sv1.mong.vn/mong/upload/'.$data['hinhanh'].'"/>
<meta property="og:locale" content="vi_VN" /> 
<meta property="og:title" content="Đọc Truyện '.$data['ten'].' Tiếng Việt"/>
<meta property="og:description" content=" '.encode($data['noidung']).'"/> 
<meta property="og:url" content="'.url().'"/> ';
   $data1['og']=$og;
loadview('template/header_truyen',$data1);
loadview("truyen/view",$data);
loadview('template/footer_truyen',$data1);

 //    loadview("template/right",$right);
exit();
?>